package uk.ac.ncl.carrent.car;

import uk.ac.ncl.carrent.*;

/**
 * @author Shiwei He
 *
 */

abstract class AbstractCar implements Car {

	private final RegistrationNumber regNumber;
	
	private final String type;
	
	private int capacity;

	private int currentFuel;
    
	private boolean status;

       
	AbstractCar(RegistrationNumber regNumber, String type) {
		this.regNumber = regNumber;
		this.type = type;
		status = false;
	}
	
	public RegistrationNumber getRegistrationNumber() {
		return regNumber;
	}

	public String getCarType(){
		return type;
	}
	
	public void setCapacity(int capacity){
		this.capacity = capacity;
	}
	public int getCapacity(){
		return capacity;
	}

	public boolean isTankFull() {
		return currentFuel == capacity;
	}

	public int getCurrentFuel() {
		return currentFuel;
	}
	
	public boolean getStatus(){
		return status;
	}

	public void setStatus(boolean status){
		this.status = status;
	}
	
	public int fuelToAdd(int fuel) {
		int fuelToAdd = fuel;
		if(isTankFull())
			return 0;
		if(currentFuel < capacity){
			if(currentFuel + fuelToAdd == capacity || currentFuel + fuelToAdd < capacity){
				currentFuel += fuelToAdd;
				return fuelToAdd;
			}
			else if(currentFuel + fuelToAdd > capacity){
				int fuelAdded = capacity - currentFuel;
				currentFuel += fuelAdded;
				return fuelAdded;
			}
		}
		return 0;
	}

	public void setCurrentFuel(int currentFuel){
		this.currentFuel = currentFuel;
	}

	public String toString(){
		return "Registration number: " + getRegistrationNumber() + "; " + "Car type: " + getCarType();
	}

}
